#ifndef REGRESSIONPARAMETER



#include<stdio.h>
#include<conio.h>


float computeYk(float b0,float b1,float xK){
    return b0+(b1*xK);
}


float computeB1(float x[],float y[],int n,float avgX,float avgY){
    int i;
    float dividend=0.0,divisor=0.0;
    for(i=0;i<n;i++){
        dividend+=x[i]*y[i];
        divisor+=x[i]*x[i];
    }
    dividend-=n*avgX*avgY;
    divisor-=n*(avgX*avgX);
    if(divisor==0)
    {
        divisor = 1;
    }
    if(dividend==0)
    {
        dividend = 1;
    }
    return dividend/divisor;
}

float computeB0(float b1,float avgX,float avgY){
    return avgY-(b1*avgX);
}

void userInputForComputeB1andB0(float *b0,float *b1){
    int n;
    int i;
    float avgX=0.0,avgY=0.0;
    system("cls");
    printf("Compute Regression Parameter B0 and B1\n\n");
    printf("Input n Programs: ");
    scanf("%d", &n);
    float x[n],y[n];
    for(i=0;i<n;i++){
        printf("\n\nProgram %d.\n",i+1);
        printf("Enter Estimated Total LOC (X): ");
        scanf("%f", &x[i]);
        printf("Enter Actual Total LOC (Y): ");
        scanf("%f", &y[i]);
        avgX+=x[i];
        avgY+=y[i];
    }
    avgX/=n;
    avgY/=n;
    (*b1) = computeB1(x,y,n,avgX,avgY);
    (*b0) = computeB0(*b1,avgX,avgY);
    //printf("\n\nThe Average of X: %f",avgX);
    //printf("\nThe Average of Y: %f",avgY);
    printf("\n\nB0 = %0.2f and B1 = %0.4f\n",*b0,*b1);
    getch();
}




#endif // REGRESSIONPARAMETER
